package com.example.demo.controller.Utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@RestControllerAdvice
public class GlobalExceptionHandlerAdvice {
  Logger log = LoggerFactory.getLogger(GlobalExceptionHandlerAdvice.class);

  @ExceptionHandler({ Exception.class }) // 复写所有异常
  public ResponseMessage handlerException(Exception e, HttpServletRequest request, HttpServletResponse response) {
    log.error("统一异常", e);
    // 处理异常
    return new ResponseMessage(500, "error", null);
  }
}
